#!/usr/bin/perl
# Version 0.2.1

$testcase = "remove_from_retr";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$success = 1;
$state = 0;
$err = 0;
@upd = (0, 0, 0);

open(DUMPFILE, $dumpfile) or $success = 0;

if($success eq 1) {
	while(<DUMPFILE>) {
		
		if($state eq 0){
			@li = split(/ /, $_);
		
			@ti = split(/:/, $li[0]);
			$secs = $ti[2] + ($ti[1] + $ti[0] * 60) * 60;
			
			if($secs > 40) {
				$state = 1;
			}
		} 
		
		if (($state > 0)&&($state < 3)) {
			# wait for the update(s) from 0.0.0.2
			if(/0\.0\.0\.2 > (.*) OSPFv2-ls_upd/) {
				$state++;
				$upd[$state] = 0;
			}
		}
		
		if(/0\.0\.0\.5 > (.*) OSPFv2-ls_upd/) {
			$upd[$state]++;

			if($state eq 2) {			
				# look if all updates from 0.0.0.5 contain the 47.11.11.0 net
				if($_ !~ /net 47\.11\.11\.0/) {
					$err = $err | 1;
				}
			}
			
			if($state eq 3) {
				# look if all updates from 0.0.0.5 do not contain the 47.11.11.0 net
				if($_ =~ /net 47\.11\.11\.0/) {
					$err = $err | 2;
				}
			}
		}
	}
	close(DUMPFILE);
	
	$verdict = 2;
	
	if($state eq 3) {
		if($err eq 0) {
			if(($upd[2] > 2)&&($upd[3] > 2)) {
				$verdict = 1;
			}
		}
	}
}

if($verdict eq 1) {
	print("RUT properly updates Retransmission list. Test PASSED.\n");
} elsif ($verdict eq 2) {
	print("RUT does not update Retransmission List properly (s=$state,e=$err,u2=$upd[2],u3=$upd[3]). Test FAILED.\n");
} else {
	print("Cannot evaluate results. Test INCONCLUSIVE.\n");
}


#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");